package com.njitzx.controller;


import com.njitzx.entity.dto.GoodsDTO;
import com.njitzx.entity.dto.GoodsPageDTO;
import com.njitzx.entity.po.Goods;
import com.njitzx.entity.vo.GoodsVO;
import com.njitzx.service.GoodsService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.njitzx.entity.vo.Result;
import org.springframework.web.bind.annotation.*;
import java.io.Serializable;

import java.util.Map;

import lombok.RequiredArgsConstructor;



import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author 周鑫
 * @since 2024-08-20
 */
@Api(tags = "商品表接口")
@RestController
@RequestMapping("/goods")
@RequiredArgsConstructor
public class GoodsController {

    private final GoodsService goodsService;

    @ApiOperation("商品表分页查询")
    @GetMapping
    public Result findPage(GoodsPageDTO goods,@RequestParam("pageNum") Integer pageNum,@RequestParam("pageSize") Integer pageSize){
        Map<String, Object> pageInfo = goodsService.findPage(pageNum,pageSize,goods);
        return Result.success(pageInfo);
    }

    @ApiOperation("根据主键查询商品表")
    @GetMapping("/{goodsId}")
    public Result findById(@PathVariable Integer goodsId){
        GoodsVO goodsVO=goodsService.findById(goodsId);
        return Result.success(goodsVO);
    }

    @ApiOperation("新增商品表")
    @PostMapping
    public Result add(@RequestBody GoodsDTO goodsDTO){
        System.out.println(goodsDTO);
         goodsService.add(goodsDTO);
        return Result.success();
    }

    @ApiOperation("修改商品表")
    @PutMapping("/{goodsId}")
    public Result modify( @PathVariable("goodsId") Integer goodsId,@RequestBody GoodsDTO goodsDTO){
        goodsDTO.setGoodsId(goodsId);
        goodsService.modify(goodsDTO);
        return Result.success();
    }

    @ApiOperation("根据主键删除商品表")
    @DeleteMapping("/{goodsId}")
    public Result removeById(@PathVariable Integer goodsId){
        goodsService.removeById(goodsId);
        return Result.success();
    }

    @PutMapping("/{goodsId}/{goodsState}")
    public Result  updateGoodsStatus(@PathVariable("goodsId") Integer goodsId,@PathVariable("goodsState")Integer goodsState){
        goodsService.updateStatus(goodsId,goodsState);
        return Result.success();
    }
}
